package net.sf.midollo.net.server;

import net.sf.midollo.io.IOStream;
import net.sf.midollo.net.io.SocketIOStream;
import net.sf.midollo.net.protocol.ProtocolFactory;
import net.sf.midollo.net.protocol.ProtocolRunner;

import java.io.IOException;
import java.net.Socket;

public class AsyncAcceptHandler implements AcceptHandler {

	protected final ProtocolFactory protocolFactory;

	public AsyncAcceptHandler(ProtocolFactory protocolFactory) {
		this.protocolFactory = protocolFactory;
	}

	public void accept(Socket clientSocket) throws IOException {
		IOStream ioRequest = new SocketIOStream(clientSocket);
		ProtocolRunner protocolRunner = new ProtocolRunner(ioRequest, this.protocolFactory);
		Thread thread = new Thread(protocolRunner);
		thread.start();
	}
}
